//
//  ShowList.m
//  IconDemo
//
//  Created by LM on 2019/9/29.
//  Copyright © 2019 TJ. All rights reserved.
//

#import "ShowListVC.h"
#import "MyTableViewCell.h"

@interface ShowListVC ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UIButton *closeBtn;

@property (nonatomic, strong) UIImageView *bgImage;

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation ShowListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.bgImage = [UIImageView new];
    self.bgImage.image = [UIImage imageNamed:@"排行榜"];
    [self.view addSubview:self.bgImage];
    UIEdgeInsets padding = UIEdgeInsetsMake(0, 0, 0, 0);
    [self.bgImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).with.insets(padding);
    }];
    
    self.closeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
//    [self.closeBtn setTitle:@"关闭" forState:UIControlStateNormal];
//    self.closeBtn.backgroundColor = [UIColor whiteColor];
    [self.closeBtn addTarget:self action:@selector(closeClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.closeBtn];
    [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.view.mas_bottom);
        make.right.mas_equalTo(self.view.mas_right);
        make.left.mas_equalTo(self.view.mas_left);
        make.height.mas_equalTo(48);
    }];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundView.backgroundColor = [UIColor clearColor];
    self.tableView.backgroundColor = [UIColor clearColor];
    [self.tableView registerNib:[UINib nibWithNibName:@"MyTableViewCell" bundle:nil] forCellReuseIdentifier:@"MyTableViewCell"];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_top).with.offset(102);
        make.left.mas_equalTo(self.view.mas_left);
        make.right.mas_equalTo(self.view.mas_right);
        make.bottom.mas_equalTo(self.closeBtn.mas_top);
    }];
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
        case 3:
        case 5:
            return 95;
            break;
        default:
            return 84;
            break;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyTableViewCell"];
//    if (cell == nil) {
//        cell = [[MyTableViewCell alloc] init];
//    }
    cell.photoImage.alpha = 0;
    cell.photoImage.layer.masksToBounds = YES;
    cell.photoImage.layer.cornerRadius = 15;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    MyTableViewCell *cell = (MyTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
    if (cell.photoImage.alpha == 0) {
        cell.photoImage.alpha = 1;
        cell.photoImage.image = self.photoImage;
    }else {
        cell.photoImage.image = nil;
        cell.photoImage.alpha = 0;
    }
}


- (void)closeClick
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
